package BD;

import android.util.Log;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

import Bean.Member;
import Bean.Organization;
import static BD.mConfig.*;
 /**
 * Created by zengyan on 2016/6/16.
 */
public class SQLiteUtil {

//     得到这个组织全部部门
    public static List getAllDepartment(Organization organization){
        List<String> allD=new ArrayList<String>();
        for (Bean.Member member :organization.getMembers()) {
            if (!isExist(allD,member.getMdepartment())){
                allD.add(member.getMdepartment());
            }
        }
        return allD;
    }

//  遍历现有部门表里有没有这个部门
    public static Boolean isExist(List<String> list,String d){
        for (String s:list) {
            if (s.equals(d)){
                return true;
            }
        }
        return false;


    }


//  查找一个组织里面的一个部门里的全部成员
    public static ArrayList<Bean.Member> getAllMember(String department, int id){
        Organization organiztion= DataSupport.where("oid=?",String.valueOf(id)).find(Organization.class,true).get(0);
        ArrayList<Bean.Member> allm=new ArrayList<Member>();
        Log.d(TAG, "getAllMember: "+organiztion.getMembers().toString());
        for (Bean.Member member:organiztion.getMembers()) {
            Log.d(TAG, "member.get:"+member.getMdepartment()+","+"department:"+department);

            if (member.getMdepartment().equals(department)){
                allm.add(member);
            }
        }
        return allm;
    }

     public static Organization getOrganiztionById(int id){
         return  DataSupport.where("oid=?",String.valueOf(id)).find(Organization.class,true).get(0);

     }




}
